#ifndef __RleManager__
#define __RleManager__

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>

struct DCT_ENCODED
{
    DCT_ENCODED(int height, int width)
    {
        tabChrominance = new cv::Vec2i*[height / 2];
        for (int i = 0; i < height / 2; ++i)
            tabChrominance[i] = new cv::Vec2i[width / 2];
        luminance = new int[height * width];
    }
    cv::Vec2i **tabChrominance;
    int *luminance;
};

struct Header
{
    int width;
    int height;
    int type;
};

class RleManager
{

private:
    FILE *file;
    Header header;

public:
    RleManager(FILE *file, Header &header);
    ~RleManager();
    bool ReadBlock(int *buffer);
    bool WriteBlockCrominance(int *block);
    bool WriteBlockLuminance(int *block);

    void WriteHeader(Header &header);
    void ReadHeader();
    Header &GetHeader();
    DCT_ENCODED *RleDecode();

private:
    void RleEncodeCrominance(int *block);
    void RleEncodeLuminance(int *block);
    void GetNextBlock(int *buffer);
    void GetNextBlockLuminance(int *buffer);

};
#endif
